<template>
    <div>
        <!-- <h3>校园超市</h3> -->
        <main>
            <div class="sear">
                <van-icon name="search" />
                <input type="text" placeholder="请输入搜索商品">
            </div>
            <Banner />
            <!-- <van-grid :border="false" :column-num="5">
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>蔬菜每日</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>肉蛋禽</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>母婴天地</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>进店必买</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>美通卡</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>早晚市</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>品牌汇</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>领券中心</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>支付优惠</span>
                </van-grid-item>
                <van-grid-item>
                    <van-image src="/img/狂.jpg" />
                    <span>直采品牌</span>
                </van-grid-item>
            </van-grid> -->
            <div class="goods">
                <li v-for="item in list" :key="item.id" @click="pushDetail(item)">
                    <img :src="item.cover" alt="">
                    <div class="desc">
                        <p>{{ item.name }}</p>
                        <div>库存：<b>{{ item.stock }}</b>份</div>
                        <p>{{ item.volume }}</p>
                        <div class="price">
                            <span>{{ item.price }}</span>
                            <button @click="pushCar(item)"> <van-icon name="shopping-cart-o" /></button>
                        </div>
                    </div>
                </li>
            </div>
            <van-pagination v-model="pageid" :total-items="total" :items-per-page="limit" @change="onHomeList"/>
        </main>
    </div>
</template>
<script>
import { getList } from '@/api';
import Banner from '@/components/Banner.vue'
export default {
    data() {
        return {
            list: [],
            pageid:1,
            limit:4,
            total:0,
        }
    },
    components: {
        Banner
    },
    mounted(){
        this.onHomeList()  
    },
    methods:{
        async  onHomeList(){
            let res=await getList({pageid:this.pageid,limit:this.limit});
            let {data,total}=res.data;
            this.list=data
            this.total=total
        },
        pushDetail(obj){
            this.$router.push({path:'/detail',params:{obj}})
        },
        pushCar(obj){
            this.$router.push({path:'/layout/cart',params:{obj}})
        }
    }
}

</script>
<style lang='scss'>
main {
    // overflow-y: auto;
    text-align: center;
    .sear{
        margin: 5px auto;
        width: 90%;
        height: 30px;
        border-radius: 15px;
        border: 1px solid #ccc;
        line-height: 30px;
        .van-icon{
            vertical-align: middle;
            margin-right: 10px;
        }
        input{
            height: 20px;
            border: none;
            outline: none;
            font-size: 14px;
        }
    }
    .van-grid-item{
        span{
            font-size: 12px;
            color: #ccc;
        }
    }
    .goods{
        li{
            text-align: left;
            margin-top: 5px;
            height: 140px;
            border-bottom: 1px solid #ccc;
            display: flex;
            align-items: center;
            justify-content: space-around;
            img{
                width: 80px;
            }
            .desc{
                width: 230px;
                p{
                    margin-top: 5px;
                    width: 230px;
                }
                div{
                    margin-top: 5px;
                    margin-bottom: 5px;
                    color: #ccc;
                    font-size: 10px;
                }
                .price{
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    span{
                        color: rgb(254, 49, 19);
                    }
                    button{
                        color: #fff;
                        background-color:rgb(254, 49, 19);
                        border-radius: 50%;
                        width: 30px;
                        height: 30px;
                        border: none;
                    }
                }
            }
        }
    }
}
</style>
